package java3_31.SuperMarket;
/**
 * *5：实现之前的超市(名称和地址属性)会员积分系统,有如下的基本功能(实现开卡和查询即可)，会员有卡号和积分两个属性：
 * 积分累计
 * 积分兑换
 * 查询剩余积分
 * 修改密码
 * 开卡
 * 退出
 * ,采用序列化的方式,每次启动如果没有超市对象,则创建新对象;否则从序列化的文件中读取,退出时保存所有数据。后续处理方式相同.
 *  SuperMarket.read()
 */

import java.io.*;
import java.util.HashSet;
import java.util.Set;

public class SuperMarket implements Serializable {
    private String name;
    private String address;
    Set<Member> member= new HashSet<>();
    public SuperMarket(){

    }
    public SuperMarket(String name, String address) {
        this.name = name;
        this.address = address;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public boolean add(Member m){
        if (!member.add(m)){
            System.out.println("会员信息重复！");
            return false;
        }
        member.add(m);
        return true;
    }
   public void marketShow(){
       System.out.println("这个商场位于：" + address + ",名字叫:" + name);
       System.out.println(member);
   }
    public static final String MAR_WEIZHI="G:\\JAVA83\\Oldliu\\src\\java3_31\\SuperMarket\\SuperMarket.txt";
    public static SuperMarket read(){
        try {
            ObjectInputStream ois = new ObjectInputStream(new FileInputStream(MAR_WEIZHI));
            Object obj = ois.readObject();
            ois.close();
            return (SuperMarket) obj;
        } catch (Exception e) {
        }
        return null;
    }
    public static void store(SuperMarket s){
        ObjectOutputStream oout= null;
        try {
            oout = new ObjectOutputStream(new FileOutputStream(MAR_WEIZHI));
            oout.writeObject(s);
            oout.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
